﻿//
// *************************************************************************************
// WP-Framework
//
// Developed by 
// Lukas Kretschmar (lkretschmar.dev@bluewin.ch)
//
// Switzerland, Copyright (c) 2012 lkretschmar
// This content is released under the MIT License (http://opensource.org/licenses/MIT).
//     
// *************************************************************************************
//
//
			

using System;
using KretschIT.WP_Fx.Core.Validation;

namespace KretschIT.WP_Fx.EasyMoq.Calls.Actions
{
    internal class ActionMock<T> : IActionMock<T>
    {
        #region Setup

        private Action<IEventsOf<T>> eventCall;

        public void Raise(Action<IEventsOf<T>> eventCall)
        {
            this.eventCall = eventCall;
        }

        private Exception exception;

        public void Throws(Exception exception)
        {
            this.exception = exception ?? new NullReferenceException();
        }

        #endregion

        #region Execute

        public virtual void Execute(T obj)
        {
            It.IsNotNull(() => obj);
            if (this.exception != null)
            {
                throw this.exception;
            }
            if (this.eventCall != null && obj is IEventsOf<T>)
            {
                this.eventCall((IEventsOf<T>)obj);
            }
        }

        #endregion
    }
}
